﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sealight.Core.DataAdapter;

namespace Sealight.Core.Domain
{
   public class UserEntity
    {
       public virtual Guid UserID { get; set; }
       public virtual string UserName { get; set; }
       public virtual string FirstName { get; set; }
       public virtual string LastName { get; set; }
       public virtual string FullName { get; set; }
       public virtual string Password { get; set; }
       public virtual DateTime LastLoginTime { get; set; }
       public virtual string EmailAddress { get; set; }
       public virtual string Photo { get; set; }       
       public virtual DateTime? BirthDate { get; set; }
       public virtual string Phone { get; set; }
       public virtual string WebsiteUrl { get; set; }
       public virtual string Token { get; set; }
       public virtual string Address { get; set; }
       public virtual string Ward { get; set; }
       public virtual DateTime? RegistedDate { get; set; }
       public virtual IList<RoleEntity> Roles { get; set; }
       public virtual JobEntity Job { get; set; }
       public virtual CityEntity City { get; set; }
       public virtual DistrictEntity District { get; set; }
       public virtual bool IsAdmin{get;set;}
       public virtual bool IsGuest { get; set; }

       public virtual user ToDataAdapter()
       {
           user user = new user
           {
               id = this.UserID,
               user_name = this.UserName,
               email_address = this.EmailAddress,
               password = this.Password,
               last_login_time = this.LastLoginTime,
               first_name = this.FirstName,
               last_name = this.LastName,
               phone = this.Phone,
               photo = this.Photo,
               registed_date = this.RegistedDate,
               ward = this.Ward,
               website_url = this.WebsiteUrl,
               birth_date = this.BirthDate,
               is_admin = this.IsAdmin,
               is_guest = this.IsGuest,
               full_name = this.FullName
           };

           if (this.Roles != null)
           {
               IList<role> roles = new List<role>();
               foreach (RoleEntity entity in this.Roles)
               {
                   roles.Add(entity.ToDataAdapter());
               }
               user.roles = roles;
           }
           if (this.Job != null)
               user.job = this.Job.ToAdapter();
           if (this.City != null)
               user.city = this.City.ToAdapter();
           if (this.District != null)
               user.district = this.District.ToAdapter();

           return user;
       }
    }
}
